﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
using DevExpress.Skins;
using DevExpress.LookAndFeel;
using DevExpress.UserSkins;
using DevExpress.XtraEditors;
using ajayumi.Platform.WinForm.WorkSpace;
using System.Linq;
using ajayumi.Test.WinForm.Dexpress.Forms;

namespace ajayumi.Test.WinForm.Dexpress
{
    public partial class FrmMain : FormBase, IParentContainer, IParentToolStripButtons
    {
        public FrmMain()
        {
            InitializeComponent();
        }


        public void SetTitle(string title)
        {
            return;
        }

        public void SetDescription(string desc)
        {
            this.tsslbModuleHelp.Text = desc;
        }

        public void LoadToolStripItems(ToolStripItem[] toolStripItems)
        {
            foreach (ToolStripItem item in this.toolStripMain.Items)
            {
                //工具条中，退出 一直显示
                if (item == this.tsbtnExit) continue;

                int count = toolStripItems.Count<ToolStripItem>(o => { return o.Equals(item); });
                item.Visible = count > 0;
            }
        }

        public void SetEnabled(ToolStripItem control, bool value)
        {
            throw new NotImplementedException();
        }

        public void RenderInContainer(WorkSpaceBase workspace)
        {
            ContainerControl containerControl = workspace.ContainerCtrl;
            Form frm = (containerControl as Form);
            frm.Activated += (sender, e) =>
            {
                this.SetTitle(workspace.Title);
                this.SetDescription(workspace.Description);
                this.LoadToolStripItems(workspace.InitToolStripItems);
            };
            frm.Deactivate += (sender, e) =>
            {
                workspace.UnRegisterAction();
            };
            frm.MdiParent = this;
            frm.Show();
        }

        public ToolStripButton AddBtn
        {
            get { return this.tsbtnAdd; }
        }

        public ToolStripButton EditBtn
        {
            get { return this.tsbtnEdit; }
        }

        public ToolStripButton DeleteBtn
        {
            get { return this.tsbtnDelete; }
        }

        public ToolStripButton ExitBtn
        {
            get { return this.tsbtnExit; }
        }

        private void FrmMain_Load(object sender, EventArgs e)
        {
            this.LoadToolStripItems(new ToolStripItem[] { });
        }


        private void tsmiTest_Click(object sender, EventArgs e)
        {
            WorkSpacesManager.Instance.ShowModule("Test1", this);
        }
        private void tsmiTest2_Click(object sender, EventArgs e)
        {
            WorkSpacesManager.Instance.ShowModule("Test2", this);
        }


    }
}